//tabbar页面跳转
function switchTab(url, duration = 0) {
	setTimeout(() => {
		uni.switchTab({
			url: /^\//.test(url) ? url : `/${url}`,
			fail: () => {

			}
		})
	}, duration)
}
//应用页面跳转
function navigateTo(url, duration = 0, animationType = 'pop-in', animationDuration = 300) {
	setTimeout(() => {
		uni.navigateTo({
			url: /^\//.test(url) ? url : `/${url}`,
			animationType,
			animationDuration
		})
	}, duration)
}
//应用页面返回
function navigateBack(delta = 1, duration = 0, animationType = 'pop-out', animationDuration = 300) {
	setTimeout(() => {
		uni.navigateBack({
			delta,
			animationType,
			animationDuration
		})
	}, duration)
}
//消息弹出
function toast(value = '', duration = 'short', verticalAlign = 'bottom', background) {
	plus.nativeUI.toast(value, {
		duration,
		verticalAlign,
		background
	})
}
//等待提示
function loading(value = '', width = '50px', height = '50px', background = 'rgba(0,0,0,.7)') {
	return plus.nativeUI.showWaiting(value, {
		width,
		height,
		background,
		loading: {
			type: 'snow'
		}
	})
}
//预览图片
function preImage(arr = [], current = 0, indicator = 'defalut') {
	let temp = []
	if (Object.prototype.toString.call(arr) == '[object Array]') {
		temp = arr
	} else {
		temp = arr.split(',')
	}
	plus.nativeUI.previewImage(temp, {
		current,
		indicator
	});
}
//获取前一页面对象
function beforePage() {
	let Pages = getCurrentPages()
	let beforePage = Pages[Pages.length - 2]
	return beforePage.$vm
}
//复制到剪切板
function setClipboardData(data) {
	uni.setClipboardData({
		data,
		showToast: false,
		success: toast('Copied to clipboard', 'short', 'bottom', 'rgba(255,170,0,.7)')
	});
}
//设置tabbar右上角文本
function setTabBarBadge(index, text) {
	uni.setTabBarBadge({
		index,
		text
	})
}
//移除tabbar右上角文本
function removeTabBarBadge(index) {
	uni.removeTabBarBadge({
		index
	})
}
//显示tabbar右上角红点
function showTabBarRedDot(index) {
	uni.showTabBarRedDot({
		index
	})
}
//隐藏tabbar右上角红点
function hideTabBarRedDot(indnex) {
	uni.hideTabBarRedDot({
		index
	})
}
//设置应用图标上显示的角标数字
function setAppBadgeNumber(num) {
	plus.runtime.setBadgeNumber(num);
}
//拨打电话
function phoneCall(number) {
	plus.device.dial(number)
}
//分享app
function shareApp(value, type = 'web') {
	plus.share.sendWithSystem({
		href: value,
		type
	})
}
//内置webview打开超链
function openWeb(url) {
	plus.runtime.openWeb(url)
}
//使用第三方程序打开超链
function openUrl(url) {
	plus.runtime.openURL(url)
}
//打开文件
function openFile(file) {
	plus.runtime.openFile(file)
}

export default {
	switchTab,
	navigateTo,
	navigateBack,
	toast,
	loading,
	preImage,
	beforePage,
	setClipboardData,
	setTabBarBadge,
	removeTabBarBadge,
	showTabBarRedDot,
	hideTabBarRedDot,
	setAppBadgeNumber,
	phoneCall,
	shareApp,
	openWeb,
	openUrl,
	openFile
}
